/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.server.main;

import com.server.database.DataEngine;
import com.server.database.UserInfo;
import java.util.List;

/**
 *
 * @author daz
 */
public class RegisterAccount {

    private String userName;
    private String userPassword;
    private String userGender;
    private String clientVersion;
    private String companyId;
    private DataEngine dataEngine = DataEngine.getInstance();

    public RegisterAccount(String userName, String password, String gender, String version, String companyId) {
        this.userName = userName.toLowerCase();
        this.userPassword = password;
        this.userGender = gender;
        this.clientVersion = version;
        this.companyId = companyId;
    }

    public void response(ClientManager parent) {
        List<UserInfo> listUserInfo = dataEngine.findUserName(userName);
        if (listUserInfo.isEmpty()) {
            //register success
            dataEngine.insertUser(userName, userPassword, userGender, companyId);
            parent.sendMessage("REGISTER|1");
        } else {
            //register failed
            parent.sendMessage("REGISTER|0");
        }
    }
}
